<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue.js 计算器</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #f0f0f0;
        }
        .calculator {
            background: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        input[type="text"], select, input[type="button"] {
            width: 100%;
            padding: 10px;
            margin: 5px 0;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        input[type="button"] {
            background-color: #007bff;
            color: white;
            cursor: pointer;
        }
        input[type="button"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>
<body>
    <div id="app" class="calculator">
        <input type="text" v-model="num1" placeholder="第一个数字"/>
        <select name="sel" id="sel" v-model="sel">
            <option value="+">+</option>
            <option value="-">-</option>
            <option value="*">x</option>
            <option value="/">/</option>
            <option value="**">^</option>
        </select>
        <input type="text" v-model="num2" placeholder="第二个数字"/>
        <input type="button" value="=" @click="cal"/>
        <input type="text" v-model="res" readonly/>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                num1: null,
                num2: null,
                sel: '+',
                res: null
            },
            methods: {
                cal() {
                    try {
                        let result;
                        if (this.sel === "+") {
                            result = parseFloat(this.num1) + parseFloat(this.num2);
                        } else if (this.sel === "-") {
                            result = parseFloat(this.num1) - parseFloat(this.num2);
                        } else if (this.sel === "*") {
                            result = parseFloat(this.num1) * parseFloat(this.num2);
                        } else if (this.sel === "/") {
                            if (this.num2 === 0) {
                                this.res = 'Error: Division by zero';
                                return;
                            }
                            result = parseFloat(this.num1) / parseFloat(this.num2);
                        } else if (this.sel === "**") {
                            result = Math.pow(parseFloat(this.num1), parseFloat(this.num2));
                        }
                        this.res = result;
                    } catch (e) {
                        this.res = 'Error: ' + e.message;
                    }
                }
            }
        });
    </script>
</body>
</html>